home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 285_02 / math.c < prev    next >
Text File  |  1990-07-08  |  1KB  |  57 lines

  1. /*--------------------------------------------------------------------------
  2. **        file:         MATH.C
  3. **        project:    hoc3, "Higher Order Calculator"
  4. */
  5.  
  6. #include <math.h>
  7. #include <errno.h>
  8. #include "hocdecl.h"
  9.  
  10. extern int errno ;
  11. double errcheck() ;
  12.  
  13. double Log( double x)
  14. {
  15.    return errcheck( log(x), "log") ;
  16. }
  17.  
  18. double Log10( double x)
  19. {
  20.    return errcheck( log10(x), "log10") ;
  21. }
  22.  
  23. double Exp( double x)
  24. {
  25.    return errcheck( exp(x), "exp") ;
  26. }
  27.  
  28. double Pow( double x, double y)
  29. {
  30.    return errcheck( pow(x, y), "exponentiation") ;
  31. }
  32.  
  33. double integer( double x)
  34. {
  35.    return (double)(long) x ;
  36. }
  37.  
  38. double Sqrt( double x)
  39. {
  40.    return errcheck( sqrt(x), "sqrt") ;
  41. }
  42.  
  43. double errcheck( double d, char *s)
  44. {
  45.     if (errno == EDOM) {
  46.         errno = 0 ;
  47.         execerror( s, "argument out of domain") ;
  48.     }
  49.     else if (errno == ERANGE) {
  50.         errno = 0 ;
  51.         execerror(s, "result out of range") ;
  52.     }
  53.  
  54.     return d ;
  55. }
  56.  
  57.